﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AidBrella.Models;
using System.Data.Objects;

namespace AidBrella.BLL
{
    public abstract class BaseModel
    {
        protected AidBrellaModelContainer _entities = new AidBrellaModelContainer();

        public AidBrellaModelContainer GetEntities()
        {
           return _entities;
        }

        /// <summary>
        /// Asks main entity to save all changes
        /// </summary>
        /// <returns></returns>
        public int SaveChanges()
        {
            if (!EntityCheck())
                return -1;

            return _entities.SaveChanges();
        }
        /// <summary>
        /// Checks that entities exist
        /// </summary>
        /// <returns>True - Success, False - Failure</returns>
        private bool EntityCheck()
        {
            if (_entities == null) return false;      
            return true;
        }

        public int SaveChanges(SaveOptions options)
        {
            if (!EntityCheck())
                return -1;

            return _entities.SaveChanges(options);
        }

        public void AcceptAllChanges()
        {
            _entities.AcceptAllChanges();
        }
    }
}